/*
https://leetcode-cn.com/problems/xor-operation-in-an-array/solution/shu-zu-yi-huo-cao-zuo-by-leetcode-solution/
 */
public class Solution1486 {
    public int xorOperation(int n, int start) {
        return ((xor((start>>1)-1)^xor((start>>1)+n-1))<<1)|(n&start&1);
    }

    int xor(int k){
        switch (k%4){
            case 0:return k;
            case 1:return 1;
            case 2:return k+1;
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1486().xorOperation(5,0));
    }
}
